<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich" xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:vm="http://full.srv.br/virtual/menu" xmlns:vl="http://full.srv.br/virtual/login"
	xmlns:ps="http://full.srv.br/postalservices" xmlns:geo="http://full.srv.br/postalservices">
	<ui:composition template="/layout/template.xhtml">
		<head>
			<ui:define name="head">
				<script>
function convertToGoogle(type){ 
	switch(type.toUpperCase()){
		case 'NORMAL':
			this.type = G_NORMAL_MAP;
			break;
		case 'HYBRID':
			this.type = G_HYBRID_MAP;
			break;
		case 'SATELLITE':
			this.type = G_SATELLITE_MAP;
			break;
		case 'DEFAULT':
		 	this.type = G_DEFAULT_MAP_TYPES ;
		 	break;
		default:
			this.type = G_NORMAL_MAP;
			break;
		}
	return this.type;
}

function convertFromGoogle(type){ 
	switch(type){
		case G_NORMAL_MAP:
		case 'G_NORMAL_MAP':
		default:
			this.type = 'NORMAL';
			break;
		case G_HYBRID_MAP:
		case 'G_HYBRID_MAP':
			this.type = 'HYBRID';
			break;
		case G_SATELLITE_MAP:
		case 'G_SATELLITE_MAP':
			this.type = 'SATELLITE';
			break;
		case G_DEFAULT_MAP_TYPES:
		case 'G_DEFAULT_MAP_TYPES':
		 	this.type = 'DEFAULT';
		 	break;
 		}
	return this.type;
}
					 
function registerListeners(map){							
	GEvent.addListener(map, 'click', function(overlay, point) {
		alert('Ponto: ' + point);
		setPlace(point.toString() + ' ' , map.getZoom());
		alert('Passei o ponto');
	});
}
						</script>
				<title><h:outputText value="#{backApp.fullTitle} " /> - Adicionar Localidade!</title>
			</ui:define>
		</head>
		<body>
			<ui:define name="body">
				<rich:panel header="Cadastro Localidades.">
					<rich:messages ajaxRendered="true" showDetail="true" layout="table" />
					<h:panelGrid border="0" columns="2" cellspacing="2">
						<a4j:form id="formLocale" ajaxSubmit="true" limitToList="true">
							<h:outputText value="#{geoManagerAddLocale.lastMensageSaveSelectedLocale}"
								rendered="#{not empty geoManagerAddLocale.lastMensageSaveSelectedLocale}" />
							<h:panelGrid border="0" cellspacing="2" columns="3">
								<h:outputLabel for="typeLocale" value="Type:" />
								<h:selectOneMenu id="typeLocale" required="true" value="#{geoManagerAddLocale.typeLocaleSelected}">
									<f:selectItems  value="#{geoManagerAddLocale.typesOfLocaleItens}" />
									<a4j:support event="onchange" status="localeEditStatus"
										action="#{geoManagerAddLocale.updateLocaleInformationsWithTypeSelected}" />
								</h:selectOneMenu>
								<rich:message for="typeLocale" />
								<h:outputLabel for="acronymLocale" value="Acronym:" />
								<h:inputText id="acronymLocale" value="#{geoManagerAddLocale.acronymSelectedLocale}" />
								<rich:message for="acronymLocale" />
								<h:outputLabel for="nameLocale" value="Name:" />
								<h:inputText id="nameLocale" value="#{geoManagerAddLocale.nameSelectedLocale}" />
								<rich:message for="nameLocale" />
								<h:outputLabel for="belongsLocale" value="Belongs:" />
								<h:selectOneMenu id="belongsLocale"  value="#{geoManagerAddLocale.superLocaleSelectedLocale}">
									<f:selectItems value="#{geoManagerAddLocale.superLocalesItens}" />
								</h:selectOneMenu>
								<rich:message for="belongsLocale" />
								<h:outputLabel for="mapPoint" value="Point on Map:"></h:outputLabel>
								<h:inputText id="mapPoint" readonly="true" value="#{geoManagerAddLocale.point}" converter="LatitudeLongitudeConverter" />
								<rich:message for="mapPoint" />
							</h:panelGrid>
							<a4j:status id="localeEditStatus" startText="processing" stopText=" "></a4j:status>
							<h:panelGrid border="0" cellspacing="2" columns="2">
								<h:commandButton value="Save" action="#{geoManagerAddLocale.saveSelectedLocale}" />
								<h:commandButton value="Reset" type="reset" />
							</h:panelGrid>
						</a4j:form>
						<!--
						<a4j:form id="formMaps" ajaxSubmit="true" limitToList="true" ajaxSingle="true">
							<rich:panel>
								<f:facet name="header">Selecione no mapa a localização mais central para esta localidade!</f:facet>
								<rich:gmap gmapVar="map" style="width:400px;height:350px" gmapKey="#{geoManagerAddLocale.mapKey}" id="gmap"
									enableDoubleClickZoom="true" oninit="showPlace(); registerListeners(map)">
								</rich:gmap>
							</rich:panel>
						</a4j:form>
						-->
					</h:panelGrid>
					<!--
					<a4j:form id="mapsFunctions" ajaxSubmit="true" limitToList="true" ajaxSingle="true">
						<a4j:jsFunction name="showPlace" data="#{geoManagerAddLocale.mapInformation}"
							oncomplete="function(){
								map.setCenter(new GLatLng(data.latitude, data.longitude),17); 
								map.setMapType(convertToGoogle(data.mapType))
								}">
						</a4j:jsFunction>
						<a4j:jsFunction oncomplete="alert('function setPlace completed')" name="setPlace"
							reRender="formLocale:mapPoint" limitToList="true">
							<a4j:actionparam name="point" assignTo="#{geoManagerAddLocale.point}" converter="LatitudeLongitudeConverter" />
							<a4j:actionparam name="zoom" assignTo="#{geoManagerAddLocale.zoom}" />
						</a4j:jsFunction>
					</a4j:form>
					-->
				</rich:panel>
				<a4j:log level="ALL" popup="false" width="300" height="200" />
			</ui:define>
		</body>
	</ui:composition>
</html>
